<!-- 修改密码 -->
<template>
    <div>

        <Modal v-model="isShow" :closable="false" width="1200" :mask-closable="false" :title="'修改密码'">
            <Form ref="dataForm" :model="dataForm" :rules="dataRule" :label-width="100">
                <FormItem label="原密码" prop="oldPassword" style="width:978px">
                    <Input v-model="dataForm.oldPassword" type="password" password size="large" placeholder="请输入原密码"></Input>
                </FormItem>
                <FormItem label="新密码" prop="newPassword" style="width:978px">
                    <Input v-model="dataForm.newPassword" type="password" password size="large" placeholder="请输入新密码"></Input>
                </FormItem>
                <FormItem label="确认密码" prop="confirmPassword" style="width:978px">
                    <Input v-model="dataForm.confirmPassword" type="password" password size="large" placeholder="请输入确认密码"></Input>
                </FormItem>
            </Form>
            <template #footer>
                <Button @click="cancel">取消</Button>
                <Button type="primary" :loading="loading" @click="submitUser">确定</Button>
            </template>
        </Modal>
    </div>
</template>
<script>


export default {
    props: [],
    data() {
        const validatePassCheck = (rule, value, callback) => {
            if (value !== this.dataForm.newPassword) {
                callback(new Error('确认密码与新密码输入不一致'));
            } else {
                callback();
            }
        };
        var validatePassword = (rule, value, callback) => {
            if (/^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{8,16}$/.test(value)) {
                callback()
            } else {
                callback(new Error('请输入8-16位 密码强度调整为 英文大小写+数字+特殊字符'));
            }
        }
        return {
            dataRule: {
                newPassword: [
                    { required: true, message: '必填项不能为空', trigger: 'change', },
                    { validator: validatePassword, trigger: 'change,blur' }
                ],
                confirmPassword: [
                    { required: true, message: '必填项不能为空', trigger: 'change' },
                    { validator: validatePassCheck, trigger: 'change,blur' }
                ],
                oldPassword: [
                    { required: true, message: '必填项不能为空', trigger: 'change' },
                    // { validator: validatePassword, trigger: 'change' }
                ],
            },
            loading: false,
            isShow: false,
            dataForm: {
                id: '',
                oldPassword: '',
                newPassword: '',
                confirmPassword: '',
            },
        }
    },
    watch: {
    },
    components: {},
    mounted() { },
    methods: {
        init() {
            this.$refs['dataForm'].resetFields();
            this.isShow = true;
        },
        submitUser() {
            this.$refs['dataForm'].validate((valid) => {
                if (!valid) {
                    return false
                } else {
                    this.loading = true
                    this.$http.$post('subsystemAuthPassWord', {
                        data: {
                            id: icu.storage.getData('userInfo').id,
                            oldPassword: this.dataForm.oldPassword,
                            newPassword: this.dataForm.newPassword,
                        }
                    }).then(res => {
                        if (res.code == 200) {
                            this.$Message.success('修改密码成功!');
                            this.cancel()
                            this.$emit('backLogin')
                            return
                        }
                        this.$Message.error(res.msg);
                        this.loading = false
                    })
                }
            })
        },
        cancel() {
            this.isShow = false;
            this.dataForm.id = ''
            this.dataForm.oldPassword = ''
            this.dataForm.newPassword = ''
            this.dataForm.confirmPassword = ''
        }
    }
}
</script>
<style scoped>
</style>
